﻿var zombies = zombies || {};

zombies.gallery = function () {
    var self = this;
    self.Gallery = ko.observableArray();
    self.Advertises = ko.observableArray();

    self.gallery1 = ko.computed(function () {
        return ko.utils.arrayFilter(self.Gallery(), function (item) {
            return (self.Gallery().indexOf(item) % 4) == 0;
        });
    });
    self.gallery2 = ko.computed(function () {
        return ko.utils.arrayFilter(self.Gallery(), function (item) {
            return (self.Gallery().indexOf(item) % 4) == 1;
        });
    });
    self.gallery3 = ko.computed(function () {
        return ko.utils.arrayFilter(self.Gallery(), function (item) {
            return (self.Gallery().indexOf(item) % 4) == 2;
        });
    });
    self.gallery4 = ko.computed(function () {
        return ko.utils.arrayFilter(self.Gallery(), function (item) {
            return (self.Gallery().indexOf(item) % 4) == 3;
        });
    });

    $.ajax({
        type: "GET",
        url: "/api/Publisher/GetGalleryWithId/" + pubId,
        contentType: "application/json",
        dataType: 'json'
    }).done(function (items) {
        for (var item in items) {
            if (items.hasOwnProperty(item)) {
                self.Gallery.push(new zombies.Gallery(items[item]))
            }
        }
    }).fail(function () {
        toastr.error('Lỗi bất thường');
    });
};

zombies.Gallery = function (item) {
    var self = this;
    self.AdvId = item.AdvId;
    self.Link = item.Link;
}

var pubId = document.URL.split('/').pop();

var galleryModel;
$(document).ready(function () {
    galleryModel = new zombies.gallery();

    ko.applyBindings(galleryModel, document.getElementById("channel_content"));

});
